package com.oneinlet.server

import io.netty.channel.Channel
import io.netty.util.AttributeKey
import java.util.concurrent.ConcurrentHashMap

/**
 * Created by WangZiHe on 2019/1/9/009
 * QQ/WeChat:648830605
 * QQ-Group:368512253
 * Blog:www.520code.net
 * Github:https://github.com/yancheng199287
 */

object ServerChannelManage {
    // val pandoraChannelAttributeKey = AttributeKey.newInstance<Channel>("pandoraChannel")

    /***
     *  存储用户端那边请求的通道，我们需要把通过代理请求的数据，再通过该通道原路返回回去
     * **/
    private val appChannelMap = ConcurrentHashMap<String, Channel>()

    /***
     *  缓存与YClient建立的通道
     * */
    lateinit var YClientChannel: Channel


    fun addAppChannel(channelId: String, channel: Channel) {
        appChannelMap[channelId] = channel
    }

    fun removeAppChannel(channelId: String) {
        appChannelMap.remove(channelId)
    }

    fun getAppChannel(channelId: String): Channel? {
        return appChannelMap.getOrDefault(channelId, null)
    }

    fun getAppChannelSize(): Int {
        return appChannelMap.size
    }

}